#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;

    string S;
    cin >> S;

    vector<long long> C(N);
    for (int i = 0; i < N; ++i) {
        cin >> C[i];
    }

    // Arrays to store the minimum cost for making the string "good"
    vector<long long> cost_same(N, LLONG_MAX), cost_diff(N, LLONG_MAX);

    // Base case: first character doesn't need to change for a different pair
    cost_diff[0] = 0;
    // First character can't be same with previous as there is no previous, set a default value
    cost_same[0] = 0;

    for (int i = 1; i < N; ++i) {
        // Making current and previous characters the same
        cost_same[i] = min(cost_same[i], cost_diff[i - 1] + C[i]);
        
        // Making current character different from the previous one
        cost_diff[i] = min(cost_diff[i], cost_diff[i - 1]);  // Extending different streak
        cost_diff[i] = min(cost_diff[i], cost_same[i - 1]);  // Changing from same to different
    }

    // The minimum cost to make the string "good" could be by having the last two characters the same or different
    long long result = min(cost_same[N - 1], cost_diff[N - 1]);
    cout << result << endl;

    return 0;
}
